import codeanticode.vision.*;

CameraGrabber cam;
FaceDetector detector;

void setup() {
  size(640, 480);
  cam = new CameraGrabber(this, 320, 240);  
  cam.start();
  detector = new FaceDetector(this, "haarcascade_frontalface_alt.xml");
  
  // Disable use of pixels if the camera image won't be drawn to the
  // screen. This avoids doing some expensive pixel conversion, which 
  // are not required for detection.
  //cam.usePixels(false);
}

void draw() {
  if (cam.read()) {
    image(cam, 0, 0, width, height);
    Rectangle[] faces = detector.detect(cam);    
    fill(200, 50, 50, 150);
    for (int i = 0; i < faces.length; i++) {
      rect(faces[i].x * width, faces[i].y * height, faces[i].w * width, faces[i].h * height);
    }    
  }
  println(frameRate);
}
